package algorithms;

import Entities.Calendar;

public class RandomRestartHC extends HillClimbing {
	private static int sizeOfRandomCalendar = 0 ;
	private int numberOfHeuristicCallsToBest = 0;
	
	public Calendar searchLocal(Calendar startCalendar) {
		Calendar next = startCalendar, best = startCalendar; // empty calendar
		while (maxOfHeuristicCalls > numberOfHeuristicCalls){ // assuming upperBound initialized > 0 	
			next = super.searchLocal(next); // hcUpperBound is limitation on the number of calendars to pass in HC
			if (next.isBetter(best)){
				numberOfHeuristicCallsToBest = numberOfHeuristicCalls;
				best = next; // save best calendar so far
			}
			next = Calendar.rand(sizeOfRandomCalendar);
			numberOfHeuristicCalls++;
		}
		return best;
	}
	
	// to start with empty calendar
	@Override
	public Calendar searchLocal(){
		return searchLocal(new Calendar(null));
	}
	
	public static void setSizeOfRandomCalendar(int numberToSet){
		sizeOfRandomCalendar = numberToSet;
	}
	
	public void reset() {
		numberOfHeuristicCalls = 0;
		numberOfHeuristicCallsToBest = 0;
	}
	
	public String toString(){
		return "SAHC Random Restart";
	}

	public int getNumberOfHeuristicCallsToBest() {
		return numberOfHeuristicCallsToBest;
	}
}